package cc.orange.adapter;

import android.text.SpannableString;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.orange.entity.ChanListEntity;
import cc.orange.utils.CircleImageView;
import cc.orange.utils.emojis.AndroidEmoji;

import cc.orange.R;


/**
 * Created by CM on 2022/10/25.
 */

public class MsgAdapter extends BaseQuickAdapter<ChanListEntity.Data, BaseViewHolder> {
    public MsgAdapter(@Nullable List<ChanListEntity.Data> data) {
        super(R.layout.item_msg, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ChanListEntity.Data item) {
        CircleImageView msg_img4 = helper.getView(R.id.msg_img4);//图片
        TextView msg_text2 = helper.getView(R.id.msg_text2);//
        TextView home_text3_num = helper.getView(R.id.home_text3_num);//消息数字
        if(item.getUnReadNum() > 0){
            home_text3_num.setVisibility(View.VISIBLE);
            home_text3_num.setText(""+item.getUnReadNum());
        }else{
            home_text3_num.setVisibility(View.GONE);
        }

//        helper.setText(R.id.home_text3_num,"");//未读消息数
        helper.setText(R.id.msg_text1,item.getName());//昵称

        helper.setText(R.id.msg_text3,item.getTime());//时间

        String content = item.getDetail();
        content = content.replace("\n", " ");
        if (content.length() > 100) {
            content = content.substring(0, 100);
        }
        msg_text2.setText(new SpannableString(AndroidEmoji.ensure(content)));//内容
        if(item.getName().contains("系统消息")){
            Glide.with(mContext).load(R.drawable.icon_mi_msg_img1)
                    .into(msg_img4);
        }else {
            Glide.with(mContext).load(item.getPhoto())
                    .into(msg_img4);
        }

    }

}
